package com.wsc.wsckeeper.app;

import java.util.ArrayList;
import java.util.List;

import com.wsc.wsckeeper.managers.BaseManager;
import com.wsc.wsckeeper.managers.DatabaseManager;
import com.wsc.wsckeeper.managers.FileServiceManager;
import com.wsc.wsckeeper.managers.PreferenceManager;
import com.wsc.wsckeeper.managers.ResourceManager;
import com.wsc.wsckeeper.managers.ScreenManager;
import com.wsc.wsckeeper.model.KModel;
import com.wsc.wsckeeper.model.KRuntimeModel;

public class KFrontManager {

	List<BaseManager> managersList;

	private static KFrontManager instance;

	private KFrontManager() {
		managersList = new ArrayList<BaseManager>();

		managersList.add(ResourceManager.getInstance());
		managersList.add(ScreenManager.getInstance());
		managersList.add(PreferenceManager.getInstance());
		managersList.add(FileServiceManager.getInstance());
		managersList.add(DatabaseManager.getInstance());
	}

	public static KFrontManager getInstance() {
		if (instance == null) {
			instance = new KFrontManager();
		}
		return instance;
	}

	public void onCreationComplete() {
		for (BaseManager manager : managersList) {
			manager.onCreationComplete();
		}
	}

	public void onRefresh() {
		for (BaseManager manager : managersList) {
			manager.onRefresh();
		}
	}

	public void onDestroy() {
		for (BaseManager manager : managersList) {
			manager.onDestroy();
		}
	}

	public void cleanData() {
		KRuntimeModel.getInstance().cleanData();
		KModel.getInstance().cleanData();
	}

	public void restartApplication() {
		restartComponents();
	}

	public void restartComponents() {

		onRefresh();
	}
}
